/**
 * 小组信息查询
 */
$(function () {
    findCoachAndLeader();
});

/**
 * 得到教练，组长并赋值
 */
function findCoachAndLeader() {
    let allCoach = myAjax('/api/stu/team/findAllCoach', {}, 'get');
    setDataCoach(allCoach.data);
    let allLeader = myAjax('/api/stu/team/findAllLeader', {}, 'get');
    setDataLeader(allLeader.data);
}
function setDataCoach(data) {
    let html = "<option value=\"\">请选择教练</option>\n";
    for (let i = 0; i < data.length; i++) {
        html+="<option value='" + data[i].nickName + "'>" + data[i].nickName + "";
    }
    return $("#coach").html(html);
}

function setDataLeader(data) {
    let html = '<option value=\"\">请选择组长</option>\n';
    for (let i = 0; i < data.length; i++) {
        html+="<option value='" + data[i].nickName + "'>" + data[i].nickName + "";
    }
    return $("#leader").html(html);
}

/**
 * 赋值
 */

/**
 提交数据
 */
function save() {
    let data = {
        teamName: $("#teamName").val(),
        classroom: $("#classroom").val(),
        stage: $("#stage").val(),
        coachName: $("#coach").val(),
        leaderName: $("#leader").val()
    };
    let result = myAjax('/api/stu/team/add', data, 'post');
    if(result.data ==='isHave'){
        alert(result.message);
    }
    if (result.data === 1) {
        alert(result.message);
        x_admin_close();
        x_admin_father_reload();
    } else {
        alert(result.message);
    }
}